package com.mio.hbase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class HbaseTest {

	@Before
    public void init() throws IOException {
		HbaseUtil.init();
    }

    //释放连接
    @After
    public void realse() {
    	HbaseUtil.destroy();
    }
	
	@Test
	public void createTable() throws IOException   {
		HbaseUtil.createTable();
	}
	@Test
	public void deleteData() throws IOException   {
//		HbaseUtil.init();
		HbaseUtil.deleteData("uid1", "uid3");
//		HbaseUtil.destroy();
	}
	@Test
	public void isColExist() throws IOException   {
//		HbaseUtil.init();
		HbaseUtil.isColExist("uid1", "uid2");
//		HbaseUtil.destroy();
	}
	
	@Test
	public void putTableData1() throws IOException   {
//		HbaseUtil.init();
		HbaseUtil.putData("uid1","uid2");
//		HbaseUtil.putData("uid3","uid1");
//		HbaseUtil.destroy();
	}
	@Test
	public void putTableData() throws IOException   {
//		String[] uids = {"uid1","uid2","uid3","uid4"};
		Map<String,List<String>> fuidMap = new HashMap<String, List<String>>();
		List<String> fuids1 = new ArrayList<String>();
//		fuids1.add("uid2");
		fuids1.add("uid3");
		fuids1.add("uid4");
		fuidMap.put("uid1", fuids1);
		
		List<String> fuids2 = new ArrayList<String>();
		fuids2.add("uid1");
		fuids2.add("uid3");
		fuids2.add("uid4");
		fuidMap.put("uid2", fuids2);
		
		List<String> fuids3 = new ArrayList<String>();
		fuids3.add("uid1");
		fuids3.add("uid2");
		fuids3.add("uid4");
		fuidMap.put("uid3", fuids3);
		
		List<String> fuids4 = new ArrayList<String>();
		fuids4.add("uid1");
		fuids4.add("uid2");
		fuids4.add("uid3");
		fuidMap.put("uid4", fuids4);
		
		for (String key : fuidMap.keySet()) {
			System.out.println("add for "+key);
			HbaseUtil.putData(key,fuidMap.get(key));
		}
		
	}
	
	@Test
	public void getDataByCF() throws IOException {
		try {
			System.out.println("start to read uid1");
			HbaseUtil.getDataByCF("uid1");
			System.out.println("start to read uid2");
			HbaseUtil.getDataByCF("uid2");
			
			System.out.println("start to read uid3");
			HbaseUtil.getDataByCF("uid3");
			
			System.out.println("start to read uid4");
			HbaseUtil.getDataByCF("uid4");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		

		
	}

}
